﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entities;

namespace HeThongNhaSach
{
    public partial class ucChamCong : UserControl
    {
        public int month = DateTime.Now.Month;
        public int year = DateTime.Now.Year;
        public List<Label> mark = new List<Label>();
        public List<Label> invi = new List<Label>();
        public List<Label> main = new List<Label>();
        public ucChamCong()
        {
            InitializeComponent();
        }
        /// <summary>
        /// tạo lable ngày
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UserControl1_Load(object sender, EventArgs e)
        {
            main.Add(lbl1);
            main.Add(lbl2);
            main.Add(lbl3);
            main.Add(lbl4);
            main.Add(lbl5);
            main.Add(lbl6);
            main.Add(lbl7);
            main.Add(lbl8);
            main.Add(lbl9);
            main.Add(lbl10);
            main.Add(lbl11);
            main.Add(lbl12);
            main.Add(lbl13);
            main.Add(lbl14);
            main.Add(lbl15);
            main.Add(lbl16);
            main.Add(lbl17);
            main.Add(lbl18);
            main.Add(lbl19);
            main.Add(lbl20);
            main.Add(lbl21);
            main.Add(lbl22);
            main.Add(lbl23);
            main.Add(lbl24);
            main.Add(lbl25);
            main.Add(lbl26);
            main.Add(lbl27);
            main.Add(lbl28);
            main.Add(lbl29);
            main.Add(lbl30);
            main.Add(lbl31);
            main.Add(lbl32);
            main.Add(lbl33);
            main.Add(lbl34);
            main.Add(lbl35);
            main.Add(lbl36);
            main.Add(lbl37);
            main.Add(lbl38);
            main.Add(lbl39);
            main.Add(lbl40);
            main.Add(lbl41);
            main.Add(lbl42);
            ViewLayout();
        }
        /// <summary>
        /// hiển thị ngày tháng chấm công
        /// </summary>
        public void ViewLayout()
        {
            label1.Text = "Tháng " + month + "/" + year;
            DateTime first = DateTime.Parse(month +"/1"+ "/" + year);
            string s = first.DayOfWeek.ToString();
            int start=1;
            switch (s)
            {
                case "Monday":
                    break;
                case "Tuesday":
                    start = 2;
                    break;
                case "Wednesday":
                    start = 3;
                    break;
                case "Thursday":
                    start = 4;
                    break;
                case "Friday":
                    start = 5;
                    break;
                case "Saturday":
                    start = 6;
                    break;
                case "Sunday":
                    start = 0;
                    break;
            }
            foreach (Label lbl in main)
            {
                lbl.Text = "";
            }
            for (int i = start; i < start+DateTime.DaysInMonth(year,month); i++)
            {
                main[i].Text = (i - start+1).ToString();
                main[i].Enabled = true;
            }
            for (int i = 0; i < start; i++)
            {
                main[i].Enabled = false;
            }
            for (int i = start + DateTime.DaysInMonth(year, month); i < 42; i++)
            {
                main[i].Enabled = false;
            }
        }
        /// <summary>
        /// tạo color cho lable
        /// </summary>
        public void UpdateColor()
        {
            foreach (Label lbl in main)
                lbl.BackColor = Color.Snow;
            foreach (Label lbl in mark)
                lbl.BackColor = Color.DarkCyan;
            foreach (Label lbl in invi)
                lbl.BackColor = Color.DarkGray;
        }

     
    }
}
